import bs4
import requests
import urllib.request
import pyvips
from pathlib import Path

path = 'https://olympics.com/tokyo-2020/zh/sports/'
img_path = 'https://olympics.com/tokyo-2020/en/d3images/pictograms/olympics/'

response = requests.get(path)
soup = bs4.BeautifulSoup(response.text, features="html.parser")

Path("svg").mkdir(parents=True, exist_ok=True)
Path("png").mkdir(parents=True, exist_ok=True)

for a in soup.select('.tk-disciplines__sequence li a'):
    filename = a.findChildren()[0].attrs['class'][1][3:]
    sport_name = a.findChildren()[1].get_text().strip().replace('/', '-')
    urllib.request.urlretrieve(img_path + filename+'.svg', 'svg/'+sport_name+'.svg')
    image = pyvips.Image.new_from_file('svg/'+sport_name+'.svg', dpi=300)
    image.write_to_file('png/'+sport_name+'.png')
